﻿namespace Rsdn.Janus.VirtualForums.AnswersMy
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using JanusLibAing;

    internal class MyAnswersFeature : VirtualForum
    {
        public MyAnswersFeature(IServiceProvider provider)
            : base(provider, null)
        {
            IIncomingFolderUpdate folderUpdate = (IIncomingFolderUpdate)provider.GetService(typeof(IIncomingFolderUpdate));
            folderUpdate.AddUpdate(this);

            Name = SR.MyAnswersFolder;
            ID = Forums.VirtualForumMyAnswersId;
        }

        /// <summary>
        /// Determines whether [is update need] [the specified MSG in].
        /// </summary>
        /// <param name="msgIn">The MSG in.</param>
        /// <returns>
        ///   <c>true</c> if [is update need] [the specified MSG in]; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsUpdateNeed(object msgIn)
        {
            bool ret = false;
            if (msgIn is Msg)
            {
                Msg msg = msgIn as Msg;
                ret = (msg.UserID == Config.Instance.SelfId);
            }

            return ret;
        }

        /// <summary>
        /// Loads the counters only.
        /// </summary>
        /// <param name="id">The forum id.</param>
        internal override void LoadCounters(int id)
        {
            MyAnswersMessage root = new MyAnswersMessage(ServiceProvider);
            using (new WaitCursor())
            {
                root.FillCounters();
            }
#if FRM_UPDATE_TRACE
            Trace.WriteLine("FRU:MyAnswers.LoadCounters");            //MLHIDE
#endif
            MessagesCount = root.RepliesCount;
            Unread = root.UnreadCount;
        }

        /// <summary>
        /// Gets the active messages.
        /// </summary>
        /// <value>The active messages.</value>
        //public override IEnumerable<IMsg> ActiveMessages
        //{
        //    get
        //    {
        //        return VirtualForumDummyForm.Instance.SelectedMessages;
        //    }
        //}

        /// <summary>
        /// Loads all topics as children in message.
        /// </summary>
        /// <param name="isLoadAll">if set to <c>true</c> [is load all].</param>
        /// <returns>root message</returns>
        protected override IMsg LoadTopicsAsChildren(bool isLoadAll)
        {
            IMsg root = MyAnswersMessage.GetMyMessagesAsChildren(ServiceProvider);
            MessagesCount = root.Count;
            Unread = root.RepliesUnread;
            RepliesToMeUnread = root.RepliesToMeUnread;

            return root;
        }
    }
}